package com.example.a_java.controller;

import com.example.a_java.dto.CategoryQuery;
import com.example.a_java.dto.RestResponse;
import com.example.a_java.entity.ProductCategory;
import com.example.a_java.service.ProductCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品分类控制器
 */
@RestController
@RequestMapping("/product/category")
@RequiredArgsConstructor
public class ProductCategoryController {

    private final ProductCategoryService productCategoryService;

    /**
     * 获取分类列表
     */
    @GetMapping("/list")
    public RestResponse<List<ProductCategory>> list(CategoryQuery query) {
        return RestResponse.success(productCategoryService.getCategoryList(query));
    }

    /**
     * 获取分类详情
     */
    @GetMapping("/{id}")
    public RestResponse<ProductCategory> getCategory(@PathVariable Long id) {
        return RestResponse.success(productCategoryService.getCategoryById(id));
    }

    /**
     * 新增分类
     */
    @PostMapping
    public RestResponse<Long> add(@RequestBody ProductCategory category) {
        return RestResponse.success(productCategoryService.addCategory(category));
    }

    /**
     * 修改分类
     */
    @PutMapping
    public RestResponse<Void> update(@RequestBody ProductCategory category) {
        productCategoryService.updateCategory(category);
        return RestResponse.success();
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{id}")
    public RestResponse<Void> delete(@PathVariable Long id) {
        productCategoryService.deleteCategory(id);
        return RestResponse.success();
    }

    /**
     * 更新分类状态
     */
    @PutMapping("/status")
    public RestResponse<Void> updateStatus(@RequestBody ProductCategory category) {
        productCategoryService.updateCategoryStatus(category);
        return RestResponse.success();
    }
} 
